home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / ak / ak4.c < prev    next >
C/C++ Source or Header  |  1987-02-14  |  5KB  |  243 lines

  1. /* enkel deze includes nodig voor soundproductie */
  2. #include "hardware/custom.h"
  3. #include "stdio.h"
  4.  
  5. #include <exec/memory.h>
  6.  
  7. #include <exec/types.h>
  8. #include <intuition/intuition.h>
  9. #include <graphics/sprite.h>
  10.  
  11. struct Preferences MyPrefs;
  12. struct RastPort *rp;
  13. struct IntuitionBase *IntuitionBase;
  14. struct GfxBase *GfxBase;
  15. struct IntuiMessage *msg;
  16. unsigned short color[3];
  17. int red[3], green[3], blue[3];
  18.  
  19. #define NUM          6
  20. #define SPRHEIGHT       16
  21. #define WORDSPERSPR     (2 * SPRHEIGHT + 4)
  22.  
  23. struct NewWindow windef = {
  24.         0,0, 640, 75,
  25.         2, 3,
  26.     FOLLOWMOUSE|MOUSEBUTTONS,
  27.         REPORTMOUSE | WINDOWDRAG | ACTIVATE|SMART_REFRESH,
  28.         NULL, NULL,
  29.         (UBYTE *) "   BAMIGA SECTOR ONE PROUDLY PRESENTS  :  <<<<<<>  AMIGA  KARATE  !  <>>>>>>   ",
  30.         NULL, NULL, 0, 0, 0, 0,
  31.         WBENCHSCREEN
  32. };
  33.  
  34. struct SimpleSprite     spr[NUM];
  35. struct Window   *win;
  36. struct ViewPort *vp;
  37. UWORD           *sprbuf;
  38. UWORD           *sprites[NUM];
  39.  
  40. LONG filesize,s1,s2,per;
  41. char *filename;
  42. short *sndbuffer, *AllocMem();
  43.  
  44. main()
  45. {
  46. int i,j;
  47. int xt,x,tw,th,tb,yprintpos,ymin_scrollraster;
  48.  
  49.  
  50.  
  51. /* aanroep van sound routine */
  52. per = 280;
  53. filename = "TAON_1";
  54. filesize = 42676;
  55. MakeSound();
  56.  
  57. openstuff ();
  58. ClearMenuStrip(win);
  59.  
  60.  
  61. color[1] = MyPrefs.color17;
  62. color[2] = MyPrefs.color18;
  63. color[3] = MyPrefs.color19;
  64.  
  65. for (i = 1; i <=3; i++)
  66. {
  67. red[i] = (color[i] >> 8) & 0x0F;
  68. green[i] = (color[i] >> 4) & 0x0F;
  69. blue[i] = color[i] & 0x0F;
  70. }
  71.  
  72. for (i = 17; i < 31; i = i + 4)
  73. {
  74. SetRGB4(vp, i, red[1], green[1], blue[1]);
  75. SetRGB4(vp, i+1, red[2], green[2], blue[2]);
  76. SetRGB4(vp, i+2, red[3], green[3], blue[3]);
  77. }
  78.  
  79.         setupsprites ();
  80.  
  81.         for (i=0; i<NUM; i++) {
  82.                 if (GetSprite (&spr[i], (long) i+1) < 0)
  83.                         die ("Sprite allocation failed.");
  84.                 spr[i].x = (win->MouseX + win->LeftEdge + MyPrefs.XOffset);
  85.                 spr[i].y = (win->MouseY + win->TopEdge + MyPrefs.YOffset - 1);
  86.                 spr[i].height = SPRHEIGHT;
  87.                 ChangeSprite (vp, &spr[i], sprites[i]);
  88.         }
  89.  
  90.  
  91.  
  92.      for(;;) {
  93.  
  94.                 if (msg = GetMsg (win->UserPort))
  95.                 {
  96.                  ReplyMsg (msg);
  97.                  if (msg->Class == MOUSEBUTTONS)
  98.                  {
  99.                   while(msg=GetMsg(win->UserPort)) ReplyMsg(msg);
  100.                   custom.dmacon = 0x0003;
  101.                   closestuff();
  102.                   exit();
  103.                  }
  104.             }
  105.  
  106.                 for (i=NUM-1; i>=0; i--) 
  107.               {
  108.         spr[i].x = (win->MouseX + win->LeftEdge + MyPrefs.XOffset);
  109.         spr[i].y = (win->MouseY + win->TopEdge + MyPrefs.YOffset - 1);
  110.         ChangeSprite (vp, &spr[i], sprites[i]);
  111.         for(j=0;j<2;j++)WaitTOF();
  112.             }
  113.            }
  114.  
  115.  
  116. }
  117.  
  118. openstuff ()
  119. {
  120. IntuitionBase = OpenLibrary ("intuition.library", 0);
  121.  
  122.     /* Geez, guys, what if Intuition isn't here?  Who cares?  We're
  123.        probably all dead anyways, if this happens... */
  124.  
  125. GfxBase = OpenLibrary ("graphics.library", 0);
  126.  
  127.     /* Ya, sure, you've pulled the Graphics.Library ROM out, right? */
  128.  
  129.         if (!(win = OpenWindow (&windef)))
  130.                 die ("No memory for window");
  131.  
  132. GetPrefs(&MyPrefs, sizeof(struct Preferences));
  133.  
  134.         vp = ViewPortAddress (win);
  135.         rp = win.RPort;
  136.  
  137. }
  138.  
  139. closestuff ()
  140. {
  141.         int i;
  142.  
  143.  
  144.         if(sndbuffer)
  145.           FreeMem(sndbuffer,filesize);
  146.  
  147.         for (i=0; i<NUM; i++)
  148.                 if (spr[i].num)
  149.                         FreeSprite ((long) spr[i].num);
  150.  
  151.         if (sprbuf)
  152.                 FreeMem (sprbuf,2L * WORDSPERSPR * NUM);
  153.         if (win)
  154.                 CloseWindow (win);
  155.         if (GfxBase)
  156.                 CloseLibrary (GfxBase);
  157.         if (IntuitionBase)
  158.                 CloseLibrary (IntuitionBase);
  159. }
  160.  
  161. die (str)
  162. char *str;
  163. {
  164.         puts (str);
  165.         closestuff ();
  166.         exit (100);
  167. }
  168.  
  169. setupsprites ()
  170. {
  171. /* This is what I stole.  Boy, I hope it wasn't copyrighted... */
  172.  
  173.         UWORD *cw;  
  174.         UWORD *ballp; 
  175.         int frame, scan;
  176.  
  177.         if (!(sprbuf = AllocMem(2L * WORDSPERSPR * NUM, MEMF_CHIP)))
  178.                 die ("Can't allocate sprite buffer.");
  179.  
  180.         cw = sprbuf;    /* current position at top of buffer */
  181.         for (frame=0; frame<NUM; frame++) {
  182.                 sprites[frame] = cw;
  183.                 *cw++ = 0;              /* poscntl */
  184.                 *cw++ = 0;
  185.                 ballp = &MyPrefs.PointerMatrix[0]; 
  186.                 for (scan=0; scan<SPRHEIGHT; scan++) {
  187.                         *cw++ = *ballp++;
  188.                         *cw++ = *ballp++;
  189.                 }
  190.                 *cw++ = 0;      /* termination */
  191.                 *cw++ = 0;
  192.         }
  193. }
  194.  
  195.  
  196. MakeSound()
  197. {
  198. LoadSound();
  199. PlaySong();
  200. }  
  201.  
  202. LoadSound()
  203. {
  204. FILE *fopen(), *fp;
  205. SHORT *ptr;
  206. LONG i;
  207.  
  208. sndbuffer = AllocMem(filesize,MEMF_CHIP);
  209. ptr = sndbuffer;
  210.  
  211. custom . dmacon = 0x0003;
  212. fp = fopen(filename,"r");
  213. if (fp == NULL) return(0);
  214.  
  215. s1 = 0; s2 =filesize;
  216. for (i=0; i<s1; i++)
  217.     getc(fp);
  218.  
  219. for (i=s1/2; i<s2/2; i++)
  220.     {
  221.     *ptr++ = getc(fp)*256 + getc(fp);
  222.     }
  223.  
  224. fclose (fp);
  225. }
  226.  
  227. PlaySong()
  228. {
  229. custom . aud[0].ac_ptr = (UWORD *)sndbuffer;
  230. custom . aud[0].ac_len = s2/2-s1/2;
  231. custom . aud[0].ac_per = per;
  232. custom . aud[0].ac_vol = 64;
  233.  
  234. custom . aud[1].ac_ptr = (UWORD *)sndbuffer;
  235. custom . aud[1].ac_len = s2/2-s1/2;
  236. custom . aud[1].ac_per = per;
  237. custom . aud[1].ac_vol = 64;
  238.  
  239. custom . dmacon = 0x8203;
  240. }
  241.  
  242.  
  243.